<template>
	<view class="container">
		<scroll-view class="scroll">
			<view class="scroll-center">
				<swiper class="swiper-container" indicator-dots indicator-color="#fff" autoplay interval="3000"
					circular>
					<block v-for="(item,index) in search" :key="index">
						<swiper-item>
							<view class="item">
								<image :src="item.pic" mode="aspectFill"></image>
							</view>
						</swiper-item>
					</block>
				</swiper>

				<view class="nav">
					<view class="item" @click="classify">
						<view class="item_img">
							<image src="/static/image/shop/2.png" mode=""></image>
						</view>
						<view class="item_txt">
							商品分类
						</view>
					</view>
					<view class="item" @click="my_Sc">
						<view class="item_img">
							<image src="/static/image/shop/3.png" mode=""></image>
						</view>
						<view class="item_txt">
							我的收藏
						</view>
					</view>
					<view class="item" @click="address">
						<view class="item_img">
							<image src="/static/image/shop/4.png" mode=""></image>
						</view>
						<view class="item_txt">
							地址管理
						</view>
					</view>
					<view class="item" @click="orderMasg">
						<view class="item_img">
							<image src="/static/image/shop/5.png" mode=""></image>
						</view>
						<view class="item_txt">
							订单管理
						</view>
					</view>
					<view class="item" @click="bill">
						<view class="item_img">
							<image src="/static/image/shop/6.png" mode=""></image>
						</view>
						<view class="item_txt">
							开票信息
						</view>
					</view>
				</view>

				<view class="list">
					<view class="tab-list" v-for="(item,index) in indexShop" :key="index" @click="details(item.id)">
						<view class="tab-img">
							<image :src="item.image" mode=""></image>
						</view>
						<view class="tab-txt">
							<view class="txt1">{{item.storeName}}</view>
							<view class="txt2">￥{{item.price}}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import $http from "@/ajax/http.js"
	export default {
		data() {
			return {
				search: [],
				indexShop: []
			}
		},
		onLoad() {
			this.shop();
			this.shopIndex()
		},
		methods: {

			shop() {
				$http.request({
					url: '/api/front/index',
				}, 2).then((res) => {
					console.log(res, "商城首页");
					this.search = res.banner
				})
			},

			shopIndex() {
				$http.request({
					url: "/api/front/index/product/3"
				}, 2).then((res) => {
					console.log(res, "首页图片");
					this.indexShop = res.list
				})
			},

			// 商品分类
			classify() {
				uni.navigateTo({
					url: '/pages/shop/classify/index'
				})
			},

			// 我的收藏
			my_Sc() {
				uni.navigateTo({
					url: '/pages/shop/myCollect/index'
				})
			},

			//商品详情跳转
			details(id) {
				uni.navigateTo({
					url: `/pages/shop/detailsPage/index?id=${id}`
				})
			},

			// 开票信息跳转
			bill() {
				uni.navigateTo({
					url: "/pages/shop/billing/index"
				})
			},
			// 地址管理
			address() {
				uni.navigateTo({
					url: "/pages/shop/address/index"
				})
			},

			// 订单管理
			orderMasg() {
				uni.navigateTo({
					url: "/pages/shop/orderMangement/index"
				})
			}

		},
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		background-color: #f5f5f5;
		display: flex;
		align-items: center;
		flex-direction: column;

		.scroll {
			height: calc(100vh);

			.scroll-center {
				display: flex;
				justify-content: center;
				flex-direction: column;
				align-items: center;
			}
		}

		.swiper-container {
			width: 694rpx;
			height: 280rpx;
			border-radius: 25rpx;
		}

		.item {
			height: 150px;
		}

		.item image {
			width: 100%;
			height: 100%;
		}

		.nav {
			width: 695rpx;
			height: 177rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			background-color: #ffffff;
			border-radius: 25rpx;
			margin-top: 23rpx;

			.item {
				height: 177rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;

				.item_img {
					width: 94rpx;
					height: 94rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					margin-bottom: 10rpx;
				}

				.item_txt {
					height: 23rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #333333;
				}
			}

		}

		.list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			width: 695rpx;
			margin-top: 23rpx;

			.tab-list {
				width: 334rpx;
				height: 465rpx;
				border-radius: 15rpx;
				margin-top: 23rpx;

				.tab-img {
					border-radius: 15rpx;
					width: 334rpx;
					height: 334rpx;

					image {
						border-top-left-radius: 15rpx;
						border-top-right-radius: 15rpx;
						width: 334rpx;
						height: 334rpx;
					}
				}

				.tab-txt {
					border-radius: 15rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: space-around;
					width: 335rpx;
					height: 131rpx;
					background-color: #ffffff;

					.txt1 {
						width: 298rpx;
						font-weight: 400;
						font-size: 26rpx;
						color: #1A1A1A;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						/* 防止换行 */
					}

					.txt2 {
						width: 298rpx;
						font-weight: bold;
						font-size: 33rpx;
						color: #DB1E00;
					}
				}
			}
		}

	}
</style>